<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var countPartitions = function (nums, k) {
      let sum = nums.reduce((a, b) => a + b)
      if (sum < 2 * k) return 0; // 情况① 排除
      const MOD = 1000000007;
      let f = new Array(k).fill(0);
      f[0] = 1;
      let ans = 1;

      for (let x of nums) {
        ans = (ans * 2) % MOD; // 总情况数
        for (let j = k - 1; j >= x; j--) {
          f[j] = (f[j] + f[j - x]) % MOD; // 滚动数组求 01背包
        }
      }
      // 对于结果是负数，需要加上 MOD
      return (ans - ((sum(f) * 2) % MOD) + MOD) % MOD;
    };
    console.log(countPartitions([1, 2, 3, 4], 4))

  </script>
</body>

</html>